/**
 * 
 */
package com.pos.modules;

import android.content.Intent;
import android.content.res.Configuration;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.pos.BaseActivity;
import com.pos.OrderService;
import com.pos.R;
import com.pos.modules.bean.UserBean;
import com.pos.modules.cashier.CashierActivity;
import com.pos.modules.fast.FastCashierActivity;
import com.pos.modules.hang.HangActivity;
import com.pos.modules.inquery.InqueryActivity;
import com.pos.modules.storage.StorageActivity2;
import com.pos.set.AppSet;
import com.pos.toolbox.PreferenceConstants;
import com.pos.toolbox.PreferenceUtils;
import com.pos.toolbox.file.FilesManager;
import com.pos.widgets.dialog.CommonDialog;


/**
 * @description:首页
 * @author cai
 * @time:2017年10月12日下午10:36:31
 */
public class MainActivity extends BaseActivity implements OnClickListener {
	private TextView text_shop, text_name, text_detail, text_account;
	private LinearLayout linear_cashier, linear_bill, linear_inquery, linear_fast,linear_storage, linear_exist,linear_sale_return;
	private UserBean userBean;
	private CommonDialog commonDialog;
	private TextView text_version;
	@Override
	public void onConfigurationChanged(Configuration newConfig) {
		super.onConfigurationChanged(newConfig);
	}

	@Override
	public void initView() {
		setContentView(R.layout.main_layout);
		text_shop = bindId(R.id.text_shop);
		text_name = bindId(R.id.text_name);
		text_detail = bindId(R.id.text_detail);
		text_account = bindId(R.id.text_account);
         linear_sale_return=bindId(R.id.linear_return);
		linear_cashier = bindId(R.id.linear_cashier);
		linear_bill = bindId(R.id.linear_bill);
		linear_inquery = bindId(R.id.linear_inquery);
		linear_fast = bindId(R.id.linear_fast);
		linear_storage = bindId(R.id.linear_storage);
		linear_exist = bindId(R.id.linear_exist);
		text_version = bindId(R.id.text_version);
		Intent intent2 = new Intent(this, OrderService.class);
	     startService(intent2);

	}

	@Override
	public void initData() {
		commonDialog = new CommonDialog(mContext);
		userBean = (UserBean) FilesManager.readObject(mContext, FilesManager.User);
		text_shop.setText(userBean.getMerName());
		text_name.setText("操作员：" + userBean.getUserName());
		text_detail.setText("门店：" + userBean.getStoreName());
		text_account.setText("账号：" + PreferenceUtils.getPrefString(mContext, PreferenceConstants.userName, ""));
		text_version.setText("版本：B型" + AppSet.getVersionName(mContext));
		startPrint();

	}

	@Override
	public void initListener() {
		linear_cashier.setOnClickListener(this);
		linear_bill.setOnClickListener(this);
		linear_inquery.setOnClickListener(this);
		linear_fast.setOnClickListener(this);
		linear_storage.setOnClickListener(this);
		linear_exist.setOnClickListener(this);
		linear_sale_return.setOnClickListener(this);

	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {

		case R.id.linear_cashier:
			startActivity(CashierActivity.class);
			break;
		case R.id.linear_bill:
			startActivity(HangActivity.class);

			break;
		case R.id.linear_inquery:
			startActivity(InqueryActivity.class);

			break;
		case R.id.linear_fast:
			startActivity(FastCashierActivity.class);

			break;
		case R.id.linear_storage:
			startActivity(StorageActivity2.class);
			
			break;
		case R.id.linear_exist:
			commonDialog.showDialog("确定退出程序？", "确定", new OnClickListener() {

				@Override
				public void onClick(View v) {
					commonDialog.dismissDialog();
					finish();

				}
			});

			break;
			case  R.id.linear_return:
				startActivity(SaleReturnActivity.class);

				break;

		default:
			break;

		}
	}

	@Override
	public void onBackPressed() {
		commonDialog.showDialog("确定退出程序？", "确定", new OnClickListener() {

			@Override
			public void onClick(View v) {
				commonDialog.dismissDialog();
				finish();

			}
		});
	}

	private void startPrint() {
		/*PrintPowerOnAndOffUtils pp = new PrintPowerOnAndOffUtils(mContext);
		pp.powerOn();
		new Handler().postDelayed(new Runnable() {
			public void run() {

				new Thread(new Runnable() {
					@Override
					public void run() {
						PrintUtils printUtils = new PrintUtils(mContext);
						printUtils.detectionPrinter();
						printUtils.printTextAndNewLine("欢迎使用收银系统");
					}
				}).start();

			}
		}, 500);*/

	}
}
